<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/6/8
 * Time: 14:38
 * Mail:87658989@qq.com
 */

namespace app\api\controller\passenger;
use app\adminapi\model\Car;
use app\adminapi\model\Driver;
use think\Db;

/**
 * @name【单位订单】
 * @baseurl【passenger】
 * @file【passenger/Unit.php】
 */
class Unit extends Base
{
    /**
     * @name【获取自有车辆和司机】
     * @desc【获取自有车辆和司机】
     * @uri【getUnitDriverCar】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * order_id $ int $ 1 $ 订单id $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息 #
     * drivers $ json $ $ 司机列表 #
     * @ driver_id $ int $ 1 $ 司机id #
     * @ name $ string $ 张三 #
     * cars $ json $$ 车辆列表 #
     * @ car_id $ int $$ 车辆id #
     * @ number $ string $$ 车牌 #
     * @ car_type_id $ int $$ 车型id #
     * 】
     */
    public function getUnitDriverCar(){
        // company_mode = 2
        $field   = 'driver_id,name';
        $company = Db::name('company')->where('company_id',$this->passengerInfo['company_id'])->find();
        if($company['company_mode'] !=1 ){
            return $this->retError(140);
        }
        $where   = ['company_id'=>$this->passengerInfo['company_id']];
        $drivers = (new Driver())->getDriverList($field,$where,1,9999);
        $data['drivers'] = $drivers[1]['data'];
        $field   = 'car_id,number,car_type_id';
        $where   = ['company_id'=>$this->passengerInfo['company_id'],'entrust_company_id'=>0];
        $cars    = (new Car())->carLlist($field,$where,1,9999);
        $data['cars'] = $cars[1]['data'];
        return $this->retSucc($data);
    }

    /**
     * @name【自有派车】
     * @desc【自有派车】
     * @uri【unitUseCar】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * order_id $ int $ 1 $ 订单id $ 1 #
     * driver_id $ int $ 1 $司机id $ 1#
     * car_id $ int $ 1$车辆id $1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败 #
     * msg $ string $  $ code=0，错误信息
     * 】
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function unitUseCar(){
        $string = 'order_id#订单@require|number/driver_id#司机@require|number/';
        $string.= 'car_id#车辆@require|number/is_return';
        $data   = $this->getBatchParam($string);
        $result = (new \app\api\logic\Driver())->receiveOrder($data['driver_id'],$data['order_id'],$data['car_id'],2);
        return $this->retAll($result[0],$result[1]);
    }
}